package structure.bridge.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import structure.bridge.Driver;

public class DriverManager {

	private static List<Driver> regists = new ArrayList<Driver>();

	public static void registerDriver(Driver driver) {
		regists.add(driver);
	}

	private static boolean isDriverAllowed(Driver driver) {
		return driver != null;
	}

	public static Connection getConnection(String url, String name, String pwd) throws SQLException {
		for (Driver driver : regists) {
			if (isDriverAllowed(driver)) {
				return driver.getConnection(url, name, pwd);
			}
		}
		System.out.println("getConnection: no suitable driver");
		throw new SQLException("No suitable driver 08001");
	}
}
